import type { Datum, EnterpriseDetail, EnterpriseListData, EnterpriseListParams, EnterpriseParams, Industry, RentBuilding, RentParams } from "@/types/enterprise"
import service, { request } from "@/utils/reuqest"


export const getEnterpriseListAPI=(params:EnterpriseListParams)=>{
  return request<EnterpriseListData>('park/enterprise','GET', params)
}

//获取行业列表
export const getIndustryListAPI=() => {
 return request<Industry[]>('park/industry')
}

//添加企业
export const createEnterpriseAPI=(data:EnterpriseParams)=>{
  return request('/park/enterprise', 'POST', data)
}
/**
 * 获取企业详情
 * @param {*} id
 * @returns
 */

//编辑企业-获取
export const getEnterpriseDetailAPI = (id: string) => {
  return request<EnterpriseParams>(`/park/enterprise/${id}`)
}
//编辑企业-提交
export const updateEnterpriseAPI=(data:Partial<EnterpriseParams>)=>{
  return request('/park/enterprise', 'PUT', data)
}

//删除企业
export const delEnterpriseAPI=(id:string)=>{
  return request(`/park/enterprise/${id}`, 'DELETE')

}
//查询可租赁楼宇
export const getBuildingListAPI = () => {
  return request<RentBuilding[]>(`/park/rent/building`)
}
/**
 * 给当前企业添加合同
 * @param {*} data
 * @returns
 */

export const  createRentAPI = (data: RentParams) => {
  return request('/park/enterprise/rent', 'POST', data)
}


/**
 * 获取企业下合同列表
 * @param {*} id
 * @returns
 */
export const getRentListAPI = (id: number) => {
  return request<Datum[]>(`/park/enterprise/rent/${id}`)
}

//退租
export const outRentAPI = (id: string) => {
  return request(`/park/enterprise/rent/${id}`, 'PUT')
}
//删除
export const deletRentAPI = (id: string) => {
  return request(`/park/enterprise/rent/${id}`, 'DELETE')
}
//获取企业信息详情
export const getEnterpriseDetailListAPI = (id: string) => {
  return request<EnterpriseDetail>(`/park/enterprise/${id}`)
}

/**
 * 下载合同文件
 */
export const downloadContract = (id: number) => {
  // ❌ 普通的写法，解析成字符串是错误的
  // return request(`/download/${id}`)

  // ✅ 第二个范型参数为 Blob，请求配置中设置 responseType: 'blob'
  return service.request<null, Blob>({
    method: 'GET',
    url: `/download/${id}`,
    responseType: 'blob' // ✅ 把二进制数据流转换成 blob 对象，用于下载
  })
}